package com.woniuxy.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Bidding;
import com.woniuxy.entity.Collect;
import com.woniuxy.entity.Sign;
import com.woniuxy.mapper.BiddingMapper;
import com.woniuxy.service.BiddingService;
@Service
public class BiddingServiceImpl implements BiddingService {

	@Autowired
	private BiddingMapper biddingMapper;
	
	
	@Transactional
	@Override
	public int addBidding(Bidding bidding) { //添加竞价记录信息
		// TODO Auto-generated method stub
		int addBidding = biddingMapper.addBidding(bidding);//s
		return addBidding;
		
	}

	@Override
	public int allCollectors(int p_id) {//收藏人数
		// TODO Auto-generated method stub
		int allCollectors= biddingMapper.allCollector(p_id);
		return allCollectors;
	}
	
	@Transactional
	@Override
	public Boolean addCollection(Collect collect) {// 添加收藏
		// TODO Auto-generated method stub
		int addCollection = biddingMapper.addCollection(collect);
		
		return addCollection ==1 ?true:false;
	}
	
	@Transactional
	@Override
	public boolean addsiginer(Sign sign) {//添加一个报名人
		  return biddingMapper.addSigner(sign)==1?true:false;//s
		
	}
	@Override
	public int allsigner(int br_id) {//查询竞价室所有报名人
		// TODO Auto-generated method stub
		int allsigner = biddingMapper.allsigner(br_id);//s
		return allsigner;
	}
	@Override
	public int[] singerAndReminder(int p_id) {//查询报名人数与提醒人数
		// TODO Auto-generated method stub
		
		int signer = biddingMapper.signer(p_id);
		System.err.println(signer+"报名");
		int reminder = biddingMapper.reminder(p_id);
		int num[]= {signer,reminder};
		return num;
	}
	
	
	
	@Override//分页查询竞价记录
	public PageInfo<Bidding> findBiddingRecords(int p_id,int pageNum,int pageSize) {//查询竞价记录
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum,pageSize);//设置分页页数与每页条数
		List<Bidding> findBiddingRecords = biddingMapper.findBiddingRecords(p_id);
		PageInfo<Bidding> pageInfo = new PageInfo<>(findBiddingRecords);
		 System.out.println("分页"+"页数："+pageNum+"每页条数:"+pageSize);
		 System.err.println(pageInfo.getPageSize());
		return pageInfo;
	}
	@Override
	public List<Bidding> findAllRecords(int p_id) {//商品所有竞价记录
		// TODO Auto-generated method stub
		List<Bidding> findBiddingRecords = biddingMapper.findBiddingRecords(p_id);		
		return findBiddingRecords;
	}
	
	
	@Override
	public BigDecimal currentPrice(int p_id) {//查询当前价格，也就是目前竞价最高高价
		// TODO Auto-generated method stub
		BigDecimal currentPrice = biddingMapper.currentPrice(p_id);
		return currentPrice;
	}

	@Override
	public Boolean addVistor(int p_id) { //增加访问量，增加热度
		// TODO Auto-generated method stub
		
		int addVistor = biddingMapper.addVistor(p_id);
		return addVistor==1?true:false;
	}
	
	
	

}
